// pages/account/succeed/index.js
var app = getApp() 
Page({

  /**
   * 页面的初始数据
   */
  data: {
		//banner
		banner:'/pages/icon/u213.png',
		// 猜你喜欢
		imgurl: app.urlimg,
		showModal: false,//亲友立减金红包
		num: '',//红包金额
    title: '',// 活动名称
    family_activity_user_id:'', // 红包id
  },
	// 返回首页，继续购物
	continue_shopping:function(){
		wx.redirectTo({
			url: '../../index/index',
		})
	},
	// 查看订单
	look_order:function(e){
		var goods_id = e.currentTarget.dataset.goods_id;
		console.log(goods_id);
		  wx.navigateTo({
			url: '../orderDetail/index?id='+goods_id,
		 })
	},
	//点击banner
	click_banner:function(){
		console.log("banner被点击，跳转到对应页面");
		// wx.redirectTo({
		// 	url: '',
		// })
	},
	// 猜你喜欢板块被点击
	like_click: function (e) {
		console.log("猜你喜欢板块被点击，跳转到id对应的商品详情");
		var goods_id = e.currentTarget.dataset.goods_id;
		console.log(goods_id);
     wx.redirectTo({
		 	url: '../../index/detail/index?id='+goods_id,
		 })
	},
	// 关闭亲友立减红包
	knoc_down:function(){
		this.setData({
			showModal:false,
		})
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
	var that=this;
  var showModal = '';
		wx.request({
			url: app.url + 'api_order/succeedOrder',
			data: {
				id:e.orderId
			},
			header: {
				'content-type': 'application/json',
				'token': wx.getStorageSync('token_key')
			}, success: function (json) {
        that.setData({
          data: json.data.result,
          order_id: e.orderId,
        })
        wx.request({
          url: app.url + 'api_family_activity/get_family_activity',
          data: {
            order_no: json.data.result.order_no // 订单号
          },
          header: {
            'content-type': 'application/json',
            'token': wx.getStorageSync('token_key')
          }, success: function (json) {
            console.log(json)
            if (json.data.result.state == 1){
              showModal = true
            }else{
              showModal = false
            }
            if (showModal == true){
              that.setData({
                showModal: showModal,
                num: json.data.result.family_activity_info.number,
                title: json.data.result.family_activity_info.name,
                family_activity_user_id: json.data.result.family_activity_user_id,
              })
            }
          }
        })

				
			}
		})

		//引用 “我的收藏” 中的 “猜你喜欢”
		wx.request({
			url: app.url + 'api_goods/get_favoriteV1',
			data: {
			},
			header: {
				'content-type': 'application/json',
				'token': wx.getStorageSync('token_key')
			}, success: function (json) {
				console.log(json);
				var selectGoodsImgs = [];
				for (var i = 0; i < json.data.result.favorite_goods.length; i++) {
					selectGoodsImgs.push(
						"/pages/icon/checkMsg.png"
					)
				}
				that.setData({
					"data.likegoods": json.data.result.likegoods,
				});
				console.log(that.data);
			}
		})
  },
	//猜你喜欢，查看商品详情
	click_goods: function (e) {
		console.log(e.currentTarget.id);
		wx.redirectTo({
			url: '/pages/index/detail/index?id=' + e.currentTarget.id,
		})
	},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
		console.log("页面上拉加载");
		//数据加载
		// wx.request({
		// 	url: '',
		// 	method: 'GET',
		// 	headers: {
		// 		'Content-Type': 'application/json'
		// 	},
		// 	success: function (res) {
		// 	},
		// 	//接口调用失败返回的函数
		// 	fail: function (err) {
		// 		console.log(err)
		// 	}
		// })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    console.log(that.data.family_activity_user_id)
    return{
      title:that.data.title,
      path: '/pages/account/succeed/knock_gold/index?id=' + that.data.family_activity_user_id, // 分享后点击页面链接
      success: function (res) {
        wx.navigateTo({
          url: '/pages/account/succeed/knock_gold/index?id=' + that.data.family_activity_user_id,
        })
      }
    }
  }
})